package gui;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.Locale;

import gui.menu.HighscoreMenu;
import data.HighscoreEntry.DIFFICULTY;
import data.Player;

import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class DialogCollection{
	
	public static JPanel defDialogPane = null;

	public static int showPlayerDialog(){
		Object[] possibilities = {2, 3, 4};
		int i = (Integer)JOptionPane.showInputDialog(defDialogPane,"Wie viele Spieler spielen mit?",
		                    "Spieleranzahl",
		                    JOptionPane.PLAIN_MESSAGE,
		                    null,
		                    possibilities,
		                    "2");

		return i;
	}
	
	public static void showMessageDialog(String msg){
		JOptionPane.showMessageDialog(defDialogPane, msg);
	}
	
	public static String showPlayerNameChangeDialog(Player pl){
		
		String newName = (String)JOptionPane.showInputDialog(defDialogPane,"Type in a new name for " + pl.getName() + ".\nThe name must be between 1 and 10 characters long\n and should not contain escape sequences.",
		                    "Player name",
		                    JOptionPane.PLAIN_MESSAGE,
		                    null,
		                    null,
		                    pl.getName());
		
		if(newName == null)newName = pl.getName();
		return newName;
	}
	
	
	public static void showNotEnoughPlayerDialog(){
		JOptionPane.showConfirmDialog(defDialogPane, "There are not enough players to play the game! Please add more players!","Not enough players",JOptionPane.PLAIN_MESSAGE);
	}
	
	public static DIFFICULTY showDeleteHighscoresDialog(DIFFICULTY difficulty){
		String difficultyString;
		switch (difficulty) {
		case EASY: difficultyString = "EASY";		
			break;
		case MEDIUM: difficultyString = "MEDIUM";
			break;
		case HARD: difficultyString = "HARD";
			break;
		default: difficultyString = "current";
			break;
		}
		String[] options = {"Delete " + difficultyString + " highscores", "Delete all highscores", "Cancel"};
		int input = (Integer) JOptionPane.showOptionDialog(defDialogPane,
			    "Deleted highscores cannot be restored. Are you sure you want to delete the highscores?",
			    "Confirm highscore delete",
			    JOptionPane.YES_NO_CANCEL_OPTION,
			    JOptionPane.QUESTION_MESSAGE,
			    null,     //do not use a custom Icon
			    options,  //the titles of buttons
			    options[2]); //default button title

		if (input == 0)return difficulty;
		else if(input == 1) return DIFFICULTY.ALL;
		else return DIFFICULTY.UNDEFINED;
	}

	public static JPanel getDefDialogPane() {
		return defDialogPane;
	}

	public static void setDefDialogPane(JPanel defDialogPane) {
		DialogCollection.defDialogPane = defDialogPane;
	}
	

}
